﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;

public class PressMachine : MonoBehaviour {

    [Header("开始位置")]
    public Vector3 upPosition;
    [Header("开始位置停留时间")]
    public float downDelay = 1f;
    [Header("开始位置到结束位置的动画时间")]
    public float downDuration = 2f;
    [Header("结束位置")]
    public Vector3 downPosition;
    [Header("结束位置停留时间")]
    public float upDelay = 0.8f;
    [Header("返回开始位置的动画时间")]
    public float upDuration = 0.8f;

    public Ease ease = Ease.OutQuad;

    private void Start() {
        transform.localPosition = upPosition;
        OnCompleteUp();
    }

    void OnCompleteDown() {
        transform.DOLocalMove(upPosition, upDuration)
                 .SetDelay(upDelay)
                 .OnComplete(OnCompleteUp)
                 .SetEase(ease)
                 .PlayForward();
    }

    void OnCompleteUp() {
        transform.DOLocalMove(downPosition, downDuration)
                 .SetDelay(downDelay)
                 .OnComplete(OnCompleteDown)
                 .SetEase(ease)
                 .PlayForward();
    }

    [ContextMenu("1.把物体当前位置设置为开始位置")]
    public void CopyPositionToUp() {
        upPosition = transform.localPosition;
    }

    [ContextMenu("2.把物体当前位置设置为结束位置")]
    public void CopyPositionToDown() {
        downPosition = transform.localPosition;
    }

    [ContextMenu("3.让物体移动到开始位置")]
    public void CopyUpToPosition() {
        transform.localPosition = upPosition;
    }

}
